home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cfdemo / cfdemo.ht_ / cfdemo.ht
Encoding:
Text File  |  1998-11-13  |  16.4 KB  |  359 lines

  1.  
  2. <HTML>
  3. <HEAD><TITLE>
  4. ChooseFont Demo</TITLE>
  5. </HEAD>
  6. <BODY bgColor=#ffffff text=#000000>
  7. <H1><font color==ff0000>Font Dialog Box</font></H1>
  8.  
  9. <P>The <B>Font </B>dialog box lets the user choose attributes for a logical 
  10. font, such as typeface name, style (bold, italic, or regular), point size, 
  11. effects (underline, strikeout, and text color), and a script (or character set). 
  12. </P>
  13. <P>You create and display a <B>Font</B> dialog box by initializing a <B>CHOOSEFONT</B>
  14. structure and passing the structure to the <B>ChooseFont</B>
  15. function. </P>
  16. <P>The following illustration shows a typical <B>Font</B> dialog box.</P>
  17. <P><IMG alt="" border=0 src="cfdemo.bmp"></P>
  18. <P>If the user clicks the <B>OK</B> button, <B>ChooseFont</B> returns TRUE and 
  19. sets the members of the <B>LOGFONT</B>
  20. structure pointed to by the <B>lpLogFont</B> member of the <B>CHOOSEFONT</B> 
  21. structure. You can use the <B>LOGFONT</B> structure with the <B>CreateFontIndirect</B>
  22. function to create a logical font. <B>ChooseFont</B> also sets other 
  23. <B>CHOOSEFONT</B> members to indicate the user's selections.</P>
  24. <P>If the user cancels the <B>Font</B> dialog box or an error occurs, <B>ChooseFont</B>
  25. returns FALSE and the contents of the <B>LOGFONT</B> structure are not defined. 
  26. You can determine the cause of an error by using the <B>CommDlgExtendedError</B> 
  27. function to retrieve the extended error value. </P></font> 
  28.  
  29. <H1><font color=#ff0000>CHOOSEFONT</font></H1>
  30.  
  31. <P>The <B>CHOOSEFONT</B> structure contains information that the <B>ChooseFont</B> 
  32. function uses to initialize the <B>Font</B> common dialog box. After the user 
  33. closes the dialog box, the system returns information about the user's selection 
  34. in this structure. </P>
  35. <PRE><CODE>typedef struct {    // cf 
  36.     DWORD        lStructSize; 
  37.     HWND         hwndOwner; 
  38.     HDC          hDC; 
  39.     LPLOGFONT    lpLogFont; 
  40.     INT          iPointSize; 
  41.     DWORD        Flags; 
  42.     DWORD        rgbColors; 
  43.     LPARAM       lCustData; 
  44.     LPCFHOOKPROC lpfnHook; 
  45.     LPCTSTR      lpTemplateName; 
  46.     HINSTANCE    hInstance; 
  47.     LPTSTR       lpszStyle; 
  48.     WORD         nFontType; 
  49.     WORD         ___MISSING_ALIGNMENT__; 
  50.     INT          nSizeMin; 
  51.     INT          nSizeMax; 
  52. } CHOOSEFONT; 
  53.  </CODE></PRE>
  54.  
  55. <H4>Members</H4>
  56.  
  57. <DL>
  58.   <DT><B>lStructSize</B> 
  59.   <DD>Specifies the length, in bytes, of the structure. 
  60.   <DT><B>hwndOwner</B> 
  61.   <DD>Identifies the window that owns the dialog box. This member can be any 
  62.   valid window handle, or it can be NULL if the dialog box has no owner. 
  63.   <DT><B>hDC</B> 
  64.   <DD>Identifies the device context (or information context) of the printer 
  65.   whose fonts will be listed in the dialog box. This member is used only if the 
  66.   <B>Flags</B> member specifies the CF_PRINTERFONTS or CF_BOTH flag; otherwise, 
  67.   this member is ignored. 
  68.   <DT><B>lpLogFont</B> 
  69.   <DD>Pointer to a <B>LOGFONT</B></A> 
  70.   structure. If you set the CF_INITTOLOGFONTSTRUCT flag in the <B>Flags</B> 
  71.   member and initialize the <B>LOGFONT</B> members, the <B>ChooseFont</B>
  72.   function initializes the dialog box with a font that is the closest possible 
  73.   match. If the user clicks the <B>OK</B> button, <B>ChooseFont</B> sets the 
  74.   members of the <B>LOGFONT</B> structure based on the user's selections. 
  75.   <DT><B>iPointSize</B> 
  76.   <DD>Specifies the size of the selected font, in units of 1/10 of a point. The 
  77.   <B>ChooseFont</B> function sets this value after the user closes the dialog 
  78.   box. 
  79.   <DT><B>Flags</B> 
  80.   <DD>A set of bit flags that you can use to initialize the <B>Font</B> common 
  81.   dialog box. When the dialog box returns, it sets these flags to indicate the 
  82.   user's input. This member can be a combination of the following flags: 
  83.   <TABLE cellPadding=0 cellSpacing=0 cols=2>
  84.     <TR vAlign=top>
  85.       <TH align=left width=49%>Flag</TH>
  86.       <TH align=left width=51%>Meaning</TH></TR>
  87.  
  88.     <TR vAlign=top>
  89.       <TD width=49%>CF_APPLY</TD>
  90.       <TD width=51%>Causes the dialog box to display the Apply button. You 
  91.         should provide a hook procedure to process WM_COMMAND
  92.         messages for the Apply button. The hook procedure can send the WM_CHOOSEFONT_GETLOGFONT
  93.         message to the dialog box to retrieve the address of the <B>LOGFONT</B></A> 
  94.         structure that contains the current selections for the font. </TD></TR>
  95.  
  96.     <TR vAlign=top>
  97.       <TD width=49%>CF_ANSIONLY</TD>
  98.       <TD width=51%>This flag is obsolete. To limit font selections to all 
  99.         scripts except those that use the OEM or Symbol character sets, use 
  100.         CF_SCRIPTSONLY. To get the Windows 3.1 CF_ANSIONLY behavior, use 
  101.         CF_SELECTSCRIPT and specify ANSI_CHARSET in the <B>lfCharSet</B> member 
  102.         of the <B>LOGFONT</B> structure pointed to by <I>lpLogFont</I>.</TD></TR>
  103.  
  104.     <TR vAlign=top>
  105.       <TD width=49%>CF_BOTH</TD>
  106.       <TD width=51%>Causes the dialog box to list the available printer and 
  107.         screen fonts. The <B>hDC</B> member identifies the device context (or 
  108.         information context) associated with the printer. This flag is a 
  109.         combination of the CF_SCREENFONTS and CF_PRINTERFONTS flags.</TD></TR>
  110.  
  111.     <TR vAlign=top>
  112.       <TD width=49%>CF_TTONLY</TD>
  113.       <TD width=51%>Specifies that <B>ChooseFont</B>
  114.         should only enumerate and allow the selection of TrueType fonts.</TD></TR>
  115.  
  116.     <TR vAlign=top>
  117.       <TD width=49%>CF_EFFECTS</TD>
  118.       <TD width=51%>Causes the dialog box to display the controls that allow 
  119.         the user to specify strikeout, underline, and text color options. If 
  120.         this flag is set, you can use the <B>rgbColors</B> member to specify the 
  121.         initial text color. You can use the <B>lfStrikeOut</B> and 
  122.         <B>lfUnderline</B> members of the <B>LOGFONT</B>
  123.         structure pointed to by <B>lpLogFont</B> to specify the initial settings 
  124.         of the strikeout and underline check boxes. <B>ChooseFont</B> can use 
  125.         these members to return the user's selections.</TD></TR>
  126.  
  127.     <TR vAlign=top>
  128.       <TD width=49%>CF_ENABLEHOOK</TD>
  129.       <TD width=51%>Enables the hook procedure specified in the 
  130.         <B>lpfnHook</B> member of this structure.</TD></TR>
  131.  
  132.     <TR vAlign=top>
  133.       <TD width=49%>CF_ENABLETEMPLATE</TD>
  134.       <TD width=51%>Indicates that the <B>hInstance</B> and 
  135.         <B>lpTemplateName</B> members specify a dialog box template to use in 
  136.         place of the default template.</TD></TR>
  137.  
  138.     <TR vAlign=top>
  139.       <TD width=49%>CF_ENABLETEMPLATEHANDLE</TD>
  140.       <TD width=51%>Indicates that the <B>hInstance</B> member identifies a 
  141.         data block that contains a preloaded dialog box template. The system 
  142.         ignores the <B>lpTemplateName</B> member if this flag is 
  143. specified.</TD></TR>
  144.  
  145.     <TR vAlign=top>
  146.       <TD width=49%>CF_FIXEDPITCHONLY</TD>
  147.       <TD width=51%>Specifies that <B>ChooseFont</B>
  148.         should select only fixed-pitch fonts.</TD></TR>
  149.  
  150.     <TR vAlign=top>
  151.       <TD width=49%>CF_FORCEFONTEXIST</TD>
  152.       <TD width=51%>Specifies that <B>ChooseFont</B> should indicate an error 
  153.         condition if the user attempts to select a font or style that does not 
  154.         exist.</TD></TR>
  155.  
  156.     <TR vAlign=top>
  157.       <TD width=49%>CF_INITTOLOGFONTSTRUCT</TD>
  158.       <TD width=51%>Specifies that <B>ChooseFont</B> should use the <B>LOGFONT</B>
  159.         structure pointed to by the <B>lpLogFont</B> member to initialize the 
  160.         dialog box controls.</TD></TR>
  161.  
  162.     <TR vAlign=top>
  163.       <TD width=49%>CF_LIMITSIZE</TD>
  164.       <TD width=51%>Specifies that <B>ChooseFont</B>
  165.         should select only font sizes within the range specified by the 
  166.         <B>nSizeMin</B> and <B>nSizeMax</B> members.</TD></TR>
  167.  
  168.     <TR vAlign=top>
  169.       <TD width=49%>CF_NOOEMFONTS</TD>
  170.       <TD width=51%>Same as the CF_NOVECTORFONTS flag.</TD></TR>
  171.  
  172.     <TR vAlign=top>
  173.       <TD width=49%>CF_NOFACESEL</TD>
  174.       <TD width=51%>When using a <B>LOGFONT</B> structure to initialize the 
  175.         dialog box controls, use this flag to selectively prevent the dialog box 
  176.         from displaying an initial selection for the font name combo box. This 
  177.         is useful when there is no single font name that applies to the text 
  178.         selection. </TD></TR>
  179.  
  180.     <TR vAlign=top>
  181.       <TD width=49%>CF_NOSCRIPTSEL</TD>
  182.       <TD width=51%>Disables the <B>Script</B> combo box. When this flag is 
  183.         set, the <B>lfCharSet</B> member of the <B>LOGFONT</B>
  184.         structure is set to DEFAULT_CHARSET when <B>ChooseFont</B>
  185.         returns. This flag is used only to initialize the dialog box.</TD></TR>
  186.  
  187.     <TR vAlign=top>
  188.       <TD width=49%>CF_NOSTYLESEL</TD>
  189.       <TD width=51%>When using a <B>LOGFONT</B> structure to initialize the 
  190.         dialog box controls, use this flag to selectively prevent the dialog box 
  191.         from displaying an initial selection for the font style combo box. This 
  192.         is useful when there is no single font style that applies to the text 
  193.         selection. </TD></TR>
  194.  
  195.     <TR vAlign=top>
  196.       <TD width=49%>CF_NOSIZESEL</TD>
  197.       <TD width=51%>When using a<B>LOGFONT</B>
  198.         structure to initialize the dialog box controls, use this flag to 
  199.         selectively prevent the dialog box from displaying an initial selection 
  200.         for the font size combo box. This is useful when there is no single font 
  201.         size that applies to the text selection. </TD></TR>
  202.  
  203.     <TR vAlign=top>
  204.       <TD width=49%>CF_NOSIMULATIONS</TD>
  205.       <TD width=51%>Specifies that <B>ChooseFont</B>
  206.         should not allow graphics device interface (GDI) font simulations.</TD></TR>
  207.  
  208.     <TR vAlign=top>
  209.       <TD width=49%>CF_NOVECTORFONTS</TD>
  210.       <TD width=51%>Specifies that <B>ChooseFont</B> should not allow vector 
  211.         font selections.</TD></TR>
  212.  
  213.     <TR vAlign=top>
  214.       <TD width=49%>CF_NOVERTFONTS</TD>
  215.       <TD width=51%>Causes the <B>Font</B> dialog box to list only 
  216.         horizontally oriented fonts.</TD></TR>
  217.  
  218.     <TR vAlign=top>
  219.       <TD width=49%>CF_PRINTERFONTS</TD>
  220.       <TD width=51%>Causes the dialog box to list only the fonts supported by 
  221.         the printer associated with the device context (or information context) 
  222.         identified by the <B>hDC</B> member.</TD></TR>
  223.  
  224.     <TR vAlign=top>
  225.       <TD width=49%>CF_SCALABLEONLY</TD>
  226.       <TD width=51%>Specifies that <B>ChooseFont</B>
  227.         should allow only the selection of scalable fonts. (Scalable fonts 
  228.         include vector fonts, scalable printer fonts, TrueType fonts, and fonts 
  229.         scaled by other technologies.)</TD></TR>
  230.  
  231.     <TR vAlign=top>
  232.       <TD width=49%>CF_SCREENFONTS</TD>
  233.       <TD width=51%>Causes the dialog box to list only the screen fonts 
  234.         supported by the system.</TD></TR>
  235.  
  236.     <TR vAlign=top>
  237.       <TD width=49%>CF_SCRIPTSONLY</TD>
  238.       <TD width=51%>Specifies that <B>ChooseFont</B> should allow selection of 
  239.         fonts for all non-OEM and Symbol character sets, as well as the ANSI 
  240.         character set. This supersedes the CF_ANSIONLY value.</TD></TR>
  241.  
  242.     <TR vAlign=top>
  243.       <TD width=49%>CF_SELECTSCRIPT</TD>
  244.       <TD width=51%>When specified on input, only fonts with the character set 
  245.         identified in the <B>lfCharSet</B> member of the <B>LOGFONT</B>
  246.         structure are displayed. The user will not be allowed to change the 
  247.         character set specified in the <B>Scripts</B> combo box.</TD></TR>
  248.  
  249.     <TR vAlign=top>
  250.       <TD width=49%>CF_SHOWHELP</TD>
  251.       <TD width=51%>Causes the dialog box to display the <B>Help</B> button. 
  252.         The <B>hwndOwner</B> member must specify the window to receive the HELPMSGSTRING
  253.         registered messages that the dialog box sends when the user clicks the 
  254.         <B>Help</B> button.</TD></TR>
  255.  
  256.     <TR vAlign=top>
  257.       <TD width=49%>CF_USESTYLE</TD>
  258.       <TD width=51%>Specifies that the <B>lpszStyle</B> member points to a 
  259.         buffer that contains style data that <B>ChooseFont</B> 
  260.         should use to initialize the <B>Font</B> <B>Style</B> combo box. When 
  261.         the user closes the dialog box, <B>ChooseFont</B> copies style data for 
  262.         the user's selection to this buffer.</TD></TR>
  263.  
  264.     <TR vAlign=top>
  265.       <TD width=49%>CF_WYSIWYG</TD>
  266.       <TD width=51%>Specifies that <B>ChooseFont</B> should allow only the 
  267.         selection of fonts available on both the printer and the display. If 
  268.         this flag is specified, the CF_BOTH and CF_SCALABLEONLY flags should 
  269.         also be specified.</TD></TR>
  270.     </TBODY>
  271.   </TABLE>
  272.   <BR>
  273.   <DT><B>rgbColors</B> 
  274.   <DD>If the CF_EFFECTS flag is set, <B>rgbColors</B> specifies the initial text 
  275.   color. When <B>ChooseFont</B>
  276.   returns successfully, this member contains the RGB value of the text color the 
  277.   user selected. 
  278.   <DT><B>lCustData</B> 
  279.   <DD>Specifies application-defined data that the system passes to the hook 
  280.   procedure identified by the <B>lpfnHook</B> member. When the system sends the 
  281.   WM_INITDIALOG
  282.   message to the hook procedure, the message's <I>lParam</I> parameter is a 
  283.   pointer to the <B>CHOOSEFONT</B> structure specified when the dialog was 
  284.   created. The hook procedure can use this pointer to get the <B>lCustData</B> 
  285.   value. 
  286.   <DT><B>lpfnHook</B> 
  287.   <DD>Pointer to a <B>CFHookProc</B>
  288.   hook procedure that can process messages intended for the dialog box. This 
  289.   member is ignored unless the CF_ENABLEHOOK flag is set in the <B>Flags</B> 
  290.   member. 
  291.   <DT><B>lpTemplateName</B> 
  292.   <DD>Pointer to a null-terminated string that names the dialog box template 
  293.   resource in the module identified by the <B>hInstance</B> member. This 
  294.   template is substituted for the standard dialog box template. For numbered 
  295.   dialog box resources, <B>lpTemplateName</B> can be a value returned by the <B>MAKEINTRESOURCE</B>
  296.   macro. This member is ignored unless the CF_ENABLETEMPLATE flag is set in the 
  297.   <B>Flags</B> member. 
  298.   <DT><B>hInstance</B> 
  299.   <DD>If the CF_ENABLETEMPLATEHANDLE flag is set in the <B>Flags</B> member, 
  300.   <B>hInstance</B> is the handle of a memory object containing a dialog box 
  301.   template. If the CF_ENABLETEMPLATE flag is set, <B>hInstance</B> identifies a 
  302.   module that contains a dialog box template named by the <B>lpTemplateName</B> 
  303.   member. If neither CF_ENABLETEMPLATEHANDLE nor CF_ENABLETEMPLATE is set, this 
  304.   member is ignored. 
  305.   <DT><B>lpszStyle</B> 
  306.   <DD>Pointer to a buffer that contains style data. If the CF_USESTYLE flag is 
  307.   specified, <B>ChooseFont</B>
  308.   uses the data in this buffer to initialize the font style combo box. When the 
  309.   user closes the dialog box, <B>ChooseFont</B> copies the string in the font 
  310.   style combo box into this buffer. 
  311.   <DT><B>nFontType</B> 
  312.   <DD>Specifies the type of the selected font when <B>ChooseFont</B> returns. 
  313.   This member can be a combination of the following values: 
  314.   <TABLE cellPadding=0 cellSpacing=0 cols=2>
  315.     <TR vAlign=top>
  316.       <TD width=39%><B>Value</B></TD>
  317.       <TH align=left width=61%>Meaning</TH></TR>
  318.  
  319.     <TR vAlign=top>
  320.       <TD width=39%>BOLD_FONTTYPE</TD>
  321.       <TD width=61%>The font weight is bold. This information is duplicated in 
  322.         the <B>lfWeight</B> member of the <B>LOGFONT</B>
  323.         structure and is equivalent to FW_BOLD.</TD></TR>
  324.  
  325.     <TR vAlign=top>
  326.       <TD width=39%>ITALIC_FONTTYPE</TD>
  327.       <TD width=61%>The italic font attribute is set. This information is 
  328.         duplicated in the <B>lfItalic</B> member of the <B>LOGFONT</B> 
  329.         structure.</TD></TR>
  330.  
  331.     <TR vAlign=top>
  332.       <TD width=39%>PRINTER_FONTTYPE</TD>
  333.       <TD width=61%>The font is a printer font.</TD></TR>
  334.  
  335.     <TR vAlign=top>
  336.       <TD width=39%>REGULAR_FONTTYPE</TD>
  337.       <TD width=61%>The font weight is normal. This information is duplicated 
  338.         in the <B>lfWeight</B> member of the <B>LOGFONT</B> structure and is 
  339.         equivalent to FW_REGULAR.</TD></TR>
  340.  
  341.     <TR vAlign=top>
  342.       <TD width=39%>SCREEN_FONTTYPE</TD>
  343.       <TD width=61%>The font is a screen font.</TD></TR>
  344.  
  345.     <TR vAlign=top>
  346.       <TD width=39%>SIMULATED_FONTTYPE</TD>
  347.       <TD width=61%>The font is simulated by the graphics device interface 
  348.         (GDI).</TD></TR>
  349.     </TBODY>
  350.   </TABLE>
  351.   <BR>
  352.   <DT><B>nSizeMin</B> 
  353.   <DD>Specifies the minimum point size a user can select. <B>ChooseFont</B> 
  354.   recognizes this member only if the CF_LIMITSIZE flag is specified. 
  355.   <DT><B>nSizeMax</B> 
  356.   <DD>Specifies the maximum point size a user can select. <B>ChooseFont</B> 
  357.   recognizes this member only if the CF_LIMITSIZE flag is specified. </DD></DL>
  358. </BODY></HTML>
  359.